package cn.rxmind.dlicense.core.rule;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.function.Predicate;

/**
 * 有效时间规则
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2021/4/16 2:38 下午
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ActiveTimeRule implements Predicate<Date> {

    private Date notBefore;
    private Date notAfter;

    /**
     * 不早于 && 不晚于
     * @param value
     * @return
     */
    @Override
    public final boolean test(Date value){

        if(getNotBefore() != null && getNotBefore().after(value)){
            return false;
        }

        if(getNotAfter() != null && getNotAfter().before(value)){
            return false;
        }
        return true;
    }
}
